let _this = this;
const db =  wx.cloud.database();

var logFunction={
  async judgeUser() {
    let judge = (await db.collection("userInfo").get()).data.length;
    // console.log(db.collection("userInfo").get().data[0]);
    console.log(judge);
    if (judge) {
    //   that.setData({
    //   judgeUser: true,
    // })
    console.log("设为T");
    getApp().globalData.judgeUser = true;
    }
  },
  async getUserProfile(that) {
console.log(getApp().globalData.judgeUser);
console.log(getApp().globalData.userInfo);
    console.log(that);
if (!getApp().globalData.judgeUser) {
  wx.getUserProfile({
        desc: '获取用户信息',
        success: (res) => {
          that.setData({
                userInfo: res.userInfo,
                hasUserInfo: true,
                judgeUser: true,
            })
            wx.setStorageSync('userInfo', res.userInfo);
            console.log(res)
            getApp().globalData.userInfo = res.userInfo;
            getApp().globalData.judgeUser = true;
            db.collection("userInfo").add({
              data:{
                userInfo: res.userInfo,
                locationList: [],
              },
              success: (res) => console.log("授权成功1"),
            });
        },
        fail: (res) => console.log(res)
    });
}
    
    // let userInfoData = (await db.collection("userInfo").get()).data.length;
    // if (!userInfoData) {
    //   db.collection("userInfo").add({
    //     data:{},
    //     success: (res) => console.log("授权成功2"),
    //   });
    // }
    return "s";
},
}
module.exports={
  logFunction:logFunction 
}
//也可以仅公开其中的一个函数如：
//
//module.exports={
//myFunction:myFunction.function1 
//}
